<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class PNR extends CI_Controller {
	
	
	public $user_data=array();
	
	function __construct()
     {
	     parent::__construct();

	
		if (!$this->session->userdata('uadmin_in')){
			
			redirect('admin/home');
			
			exit();
		}
		
		$this->lang->load('info',$this->config->item("language"));
		$this->user_data["uadmin_name"] = $this->session->userdata('uadmin_name');
		$this->user_data["uadmin_userid"] = $this->session->userdata('uadmin_userid');
		$this->user_data["uadmin_account"] = $this->session->userdata('uadmin_account');
		$this->user_data["uadmin_maincurrency"] = $this->session->userdata('uadmin_maincurrency');

     }
     

	public function bookpnr()
	{
		
		$data = array();
	   	$data['css'][0] = '<link rel="stylesheet" type="text/css" href="'.site_url('css/validator.css').'" />';
	   	$data['title'] ="book PNR";
	  
	   	$airoption =lang("aircompany");
	   	$airlist['']='=='.lang("home_allairline").'==';
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   	$data['selairline']=form_dropdown('airline', $airlist, '','style="width:164px"');

	 
	   	$data['Find_a_Flight']	=lang("Find_a_Flight");
	   	$data['home_Flight_Type']=lang('home_Flight_Type');
		$data['home_From']       =lang('home_From');
		$data['home_To']         =lang('home_To');
		$data['home_Depart']     =lang('home_Depart');
		$data['home_Return']     =lang('home_Return');
		$data['home_Airline']    =lang('home_Airline');
		$data['home_Find']       =lang('home_Find');
		$data['home_oneway']     =lang('home_oneway');
		$data['home_roundtrip']  =lang('home_roundtrip');
		$data['home_Find']		=lang('home_Find');

		$this->load->view("admin/pnr/bookPNR",$data);
	}
	

	
	public function queryflight2()
	{
		$data = array();
		//查询航班
		$this->load->model('PNR_model');
		
		$arairinfo=array();
		
		
		$data['title']="选择航班";
		$sFromCity=$this->input->post("FromCityCode");	//出发城市
		$sDestCity=$this->input->post("DestCityCode");	//目的城市		
		$sLeaveDate=$this->input->post("DepartDate");	//航班日期
		$data["DoubleTrip"] =1;
		$data["isback"]	=0;	//是否回程
		
		$isPFD="FD"; //是否使用私有运价；
		//$sFromCity="SZX";
		//$sDestCity="SHA";
		//$sLeaveDate="2011-05-17";
		$sAirline = "";
		$arairinfo=$this->PNR_model->avflight($sFromCity,$sDestCity,$sLeaveDate,$sAirline,false,1,$isPFD);

		$data['arairinfo']=$arairinfo;
		
		$this->load->view('ajax/queryflight2',$data);
	}
	
	//预订编码
	public function bookflight()
	{
		$data = array();
	   	$data['css'][0] = '<link rel="stylesheet" type="text/css" href="'.site_url('css/validator.css').'" />';
	   	$data['title'] ='-book';
	   	
	   	//ѡпĬֵ
	   	$data['sDepartDate']	=$this->input->post("DepartDate");
	   	$data['sReturnDate']	=$this->input->post("ReturnDate");
	   	
		$data["isback"]		=$this->input->post("isback");	//Ƿس
		$data["goFlightData"]	=$this->input->post("goFlightData"); //ȥ̺
		
	   	if($this->input->post("go_flightinfo")=="")
	   	{
	   		redirect("home");	
	   	}
	 
	   	$airoption =lang("aircompany");
	   	$airlist['']='==All airline==';
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   	$data['selairline']=form_dropdown('airline', $airlist, '','style="width:164px"');
	   
	   
	   	$this->load->model('Air_model');
	   	$this->load->model('Policy_model');
	   	$data['flightdata']		=$this->input->post("go_flightinfo");
	   	$data['flightbackdata']	=$this->input->post("back_flightinfo");
	   	$arairinfo=$this->Air_model->getarrbookinfo($this->input->post("go_flightinfo"),$this->input->post("back_flightinfo"));	   	
	   	
	   	$data['arairinfo']=$arairinfo;
	   	
	   	$data["TGQNote"]=$this->Policy_model->get_TGQNotebyID($arairinfo[0]["PFDID"]);
	   	$data['sFromcitycode']	=$arairinfo[0]['fromport'];
	   	$data['sDestcitycode']	=$arairinfo[0]['destport'];
	   	
	   	$this->load->model("Agent_model");
	   	$agentInfo=$this->Agent_model->get_agent($this->user_data["uadmin_userid"]);
	   	
	   	$data["mainCurrency"]	=$agentInfo["MainCurrency"];
	   	
	   	$idType =lang("idType");

	   	$data['selCTType']=form_dropdown('CTType[]',$idType, '','id="sel_CTType_REPLACE_INDEX"');
	   	
	   	
	   	$data["txLinkMan"]=$this->user_data["uadmin_name"];
	   	$data["txmobile"]=$agentInfo["Tel"];
	   	$data["txmobile2"]="";
	   	$data["txEmail"]="";
	   	
		$this->load->view('admin/pnr/bookflight',$data);
	}
	
	
	
	public function createPNR()
	{
		$user_data1["mainCurrency"]=$this->user_data["uadmin_maincurrency"];
		$user_data1["user_account"]="admin_".$this->user_data["uadmin_account"];
		$user_data1["user_name"]=$this->user_data["uadmin_name"];
		
		$user_data1["AgentCode"]=$this->user_data["uadmin_account"];
		$user_data1["AgentName"]=$this->user_data["uadmin_name"];
		
		$this->load->model("PNR_model");
		$bookresult = $this->PNR_model->create_PNR_Only($_POST,$user_data1);
		
		echo '<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>';
    		if($bookresult[0])
    		{
				echo "Booking success. Your PNR: $bookresult[1]";
    		}else
    		{
    			echo "booking fail";
    		}
		$url = site_url("admin/pnr/bookpnr");
		echo '<br><a href=# onclick="window.location.href=\''.$url.'\';">Retrun</a>';
	}
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */